package mygang.model.constructor;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.*;
import mygang.model.BaseModel;
import mygang.model.Option;
import mygang.model.OptionInterface;
import mygang.model.constructor.field.Field;

/**
 *
 * @author Volodymyr Lavrynovych <volodya.lavrynovych@gmail.com>
 * date: 22/09/2012
 */
@Entity
@Table(name = "STEP")
public class Step extends BaseModel implements Serializable, OptionInterface {

    @Id
    @Column(name = "STEP_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    
    @ManyToMany(cascade = {CascadeType.REFRESH}, fetch = FetchType.EAGER)
    @JoinTable(name = "STEP_FIELD_MAP",
    joinColumns = {@JoinColumn(name = "STEP_ID")},
    inverseJoinColumns = {@JoinColumn(name = "FIELD_ID")})
    private Set<Field> fields;
    
    @Column(name = "STEP_NAME")
    private String title;
    
    @Column(name = "STEP_DESCRIPTION")
    private String description;
    
    public Step() {
    }
    
    public Step(long id) {
        this.id = id;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Set<Field> getFields() {
        return fields;
    }

    public void setFields(Set<Field> fields) {
        this.fields = fields;
    }
    
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Option toOption() {
        return new Option(getId(), getTitle());
    }
}